package com.sumainfor.pc.market.controller.servicemanger;

import com.sumainfor.common.entity.ParentDeptVo;
import com.sumainfor.common.entity.SysUserVo;
import com.sumainfor.common.util.ContextUtils;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.DmHousingInfoService;
import com.sumainfor.pc.market.service.SeHousingInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 服务中心房源定价
 */
@RestController
@RequestMapping("/servicemanger/SeHousingInfo")
public class SeHousingInfoController implements Serializable {
    @Autowired
    private SeHousingInfoService seHousingInfoService;
    /**
     *查询房源定价列表
     * @param
     * @return
     */
    @GetMapping("/getSeHousingInfoList")
    public JsonResult getRepairList(@RequestParam Map<String,Object>params, Pager pager){
        //获取当前登录人的服务中心编号
        SysUserVo userVo = ContextUtils.getSysUser();
        ParentDeptVo vo = null;
        for (int i = 0; i < userVo.getLength(); i++) {
            ParentDeptVo vo1 = userVo.getParentDeptVo();
            if (vo1.getType().equals(3)) {
                vo = vo1;
                break;
            }
        }
        if (vo!=null){
            params.put("area_id",vo.getDeptId());//当前登录人的服务中心编号
            System.out.println("area_id:"+vo.getDeptId());
        }
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=seHousingInfoService.getSeHousingInfoListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=seHousingInfoService.getSeHousingInfoList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *查询定价详情房间配置列表
     * @param
     * @return
     */
    @GetMapping("/getSeHousingInfoListByHouId")
    public JsonResult getSeHousingInfoListByHouId(@RequestParam Map<String,Object>params){
        return seHousingInfoService.getSeHousingInfoListByHouId(params);

    }
    /**
     * 房源定价
     */
    @PostMapping("/updateSeHousingInfo")
    public JsonResult updateHousingHouInfo(@RequestBody Map<String,Object>params){
        JsonResult result=new JsonResult();
        int resultsjk=seHousingInfoService.updateSeHousingInfo(params);
        if (resultsjk>0){
            result.putSuccess("操作成功");
        }else{
            result.putFailed("服务器繁忙");
        }
        return  result;
    }
}
